package com.yeban.base.day03.homework;

import java.util.Scanner;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/9/27
 */
// 求3.1415926...=(1-1/3+1/5-1/7+1/9..........)*4
public class Test04 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.print("请输入迭代次数n：");
        int n = sc.nextInt();

        double sum = 0;
        for (long i = 1; i <= n; i++) {
            if(i % 2 == 0) {
                sum -= 4 / (double)(2 * i - 1);
            } else {
                sum += 4 / (double)(2 * i - 1);
            }
        }
        System.out.println(sum);

    }
}
